package com.woniuxy.hrp.web;

import com.woniuxy.hrp.entity.Department;
import com.woniuxy.hrp.entity.Hospital;
import com.woniuxy.hrp.entity.PageBean;
import com.woniuxy.hrp.service.DepartmentService;
import com.woniuxy.hrp.service.HospitalService;
import com.woniuxy.hrp.unityhandler.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: hrph
 * @ClassName IndexController
 * @description:门户数据展示
 * @author: LRW
 * @create: 2022-09-01 00:26
 * @Version 1.0
 **/
@CrossOrigin
@Transactional
@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    /***
     * @description: 查询系统内所有医院（首页数据展示）
     * @param:
     * @return: com.woniuxy.hrp.unityhandler.ResponseEntity
     * @author Lrw
     * @date: 2022/9/1 0:21
     */
    @GetMapping("/getAllHospitals/{page}")
    public ResponseEntity getAllHospitals(@PathVariable Integer page){
        PageBean<Hospital> pageBean = hospitalService.getByPage(page);
        return new ResponseEntity("200","ok",pageBean);
    }

    /***
     * @description: 根据名字模糊查询医院
     * @param: hospital
     * @return: com.woniuxy.hrp.unityhandler.ResponseEntity
     * @author Lrw
     * @date: 2022/9/1 0:31
     */
    @GetMapping("/getHospitalByNameVag/{page}/{name}")
    public ResponseEntity getHospitalByNameVaguely(@PathVariable("page") Integer page,@PathVariable("name") String name){
        PageBean<Hospital> hospitals = hospitalService.getByNameAndPageVaguely(page, name);
        return new ResponseEntity(hospitals);
    }

    /***
     * @description: 根据医院名字模糊查询
     * @param: name
     * @return: com.woniuxy.hrp.unityhandler.ResponseEntity
     * @author Lrw
     * @date: 2022/9/3 11:52
     */
    @GetMapping("/getHospitalByName/{name}")
    public ResponseEntity getHospitalByName(@PathVariable String name){
        List<Hospital> hospitals = hospitalService.getByNameVag(name);
        return new ResponseEntity("200","ok",hospitals);
    }

    /***
     * @description: 查询指定医院的详情及所有科室
     * @param: hospital
     * @return: com.woniuxy.hrp.unityhandler.ResponseEntity
     * @author Lrw
     * @date: 2022/9/1 0:30
     */
    @GetMapping("/getHospDetails/{hospId}")
    public ResponseEntity getHospitalDetailById(@PathVariable int hospId){
        Hospital hospital = hospitalService.getById(hospId);
        return new ResponseEntity("200","ok",hospital);
    }


    /***
     * @description: 根据医院id查所有科室
     * @param: hospId
     * @return: com.woniuxy.hrp.unityhandler.ResponseEntity
     * @author Lrw
     * @date: 2022/9/3 20:32
     */
    @GetMapping("/getDepts/{hospId}")
    public ResponseEntity getDepts(@PathVariable int hospId){
        List<Department> departments = departmentService.getDepartmentsByHospitalId(hospId);
        return new ResponseEntity("200","ok",departments);
    }

    /***
     * @description: 查指定医院的所有一级科室
     * @param:
     * @return: com.woniuxy.hrp.unityhandler.ResponseEntity
     * @author Lrw
     * @date: 2022/9/4 0:46
     */
    @GetMapping("/getParentDepts/{hospId}")
    public ResponseEntity getParentDepts(@PathVariable int hospId){
        List<Department> depts = departmentService.getAllParentDepts(hospId);
        return new ResponseEntity("200","ok",depts);
    }

    /***
     * @description: 根据父id查所有二级科室
     * @param: pId
     * @return: com.woniuxy.hrp.unityhandler.ResponseEntity
     * @author Lrw
     * @date: 2022/9/4 0:47
     */
    @GetMapping("/getChildrenDepts/{pId}")
    public ResponseEntity getChildrenDeptsByPid(@PathVariable int pId){
        List<Department> depts = departmentService.getChildrenByPid(pId);
        return new ResponseEntity("200","ok",depts);
    }




}
